package fantasyfootball.data.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 * Class: 605.441 
 * Group: Richard Koretke, Kay Jantharasorn, Israel Rivera.
 * 
 * @author Israel Rivera
 * 
 */
@Entity(name="FantasyTeam")
public class FantasyTeam implements Serializable{

	private static final long serialVersionUID = -7758742421584168126L;
	
	private String teamName;
	private FantasyManager fantasyManager;
	private FantasyLeague fantasyLeague;
	private Integer wins;
	private Integer loses;
	
	private BigDecimal totalPoints;
	
	private Set<FantasyRoster> fantasyRosters;
	private Set<FantasyTransaction> fantasyTransactions;
	
	@Id
	@Column(name="TeamName", nullable=false)
	public String getTeamName() {
		return teamName;
	}

	public void setTeamName(String teamName) {
		this.teamName = teamName;
	}
	
	@JoinColumn(name="LogonName", nullable=false)
	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	public FantasyManager getFantasyManager() {
		return fantasyManager;
	}

	public void setFantasyManager(FantasyManager fantasyManager) {
		this.fantasyManager = fantasyManager;
	}
	
	@JoinColumn(name="LeagueName", nullable=false)
	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	public FantasyLeague getFantasyLeague() {
		return fantasyLeague;
	}

	public void setFantasyLeague(FantasyLeague fantasyLeague) {
		this.fantasyLeague = fantasyLeague;
	}
	
	@Column(name="Wins", nullable=false)
	public Integer getWins() {
		return wins;
	}

	public void setWins(Integer wins) {
		this.wins = wins;
	}
	
	@Column(name="Loses", nullable=false)
	public Integer getLoses() {
		return loses;
	}

	public void setLoses(Integer loses) {
		this.loses = loses;
	}
	
	@Column(name="TotalPoints", nullable=false)
	public BigDecimal getTotalPoints() {
		return totalPoints;
	}

	public void setTotalPoints(BigDecimal totalPoints) {
		this.totalPoints = totalPoints;
	}
	
	@OneToMany(fetch=FetchType.EAGER, mappedBy="fantasyTeam")
	public Set<FantasyRoster> getFantasyRosters() {
		return fantasyRosters;
	}

	public void setFantasyRosters(Set<FantasyRoster> fantasyRosters) {
		this.fantasyRosters = fantasyRosters;
	}
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy="fantasyTeam")
	public Set<FantasyTransaction> getFantasyTransactions() {
		return fantasyTransactions;
	}

	public void setFantasyTransactions(Set<FantasyTransaction> fantasyTransactions) {
		this.fantasyTransactions = fantasyTransactions;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((teamName == null) ? 0 : teamName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FantasyTeam other = (FantasyTeam) obj;
		if (teamName == null) {
			if (other.teamName != null)
				return false;
		} else if (!teamName.equals(other.teamName))
			return false;
		return true;
	}
}